import 'package:flutter/material.dart';

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final _usernameController = TextEditingController();
  final _passwordController = TextEditingController();

  @override
  void dispose() {
    _usernameController.dispose();
    _passwordController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('登录'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: <Widget>[
            TextField(
              controller: _usernameController,
              decoration: InputDecoration(
                labelText: '账号',
              ),
            ),
            TextField(
              controller: _passwordController,
              decoration: InputDecoration(
                labelText: '密码',
              ),
              obscureText: true,
            ),
            ElevatedButton(
              onPressed: () {
                if (_usernameController.text == 'root' && _passwordController.text == '123456') {
                  // 如果账号和密码正确，跳转到主页面
                  Navigator.pushReplacementNamed(context, '/home');
                } else {
                  // 如果账号或密码不正确，显示错误消息
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text('账号或密码错误！')),
                  );
                }
              },
              child: Text('登录'),
            ),
          ],
        ),
      ),
    );
  }
}